package leetcode_周赛._2022._202201._30;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yzh
 * @version 1.0
 * @date 2022/1/30 0:50
 */
public class _5981 {
    public static void main(String[] args) {
        System.out.println(new _5981().maxScoreIndices(new int[]{0, 0, 0}));
    }

    public List<Integer> maxScoreIndices(int[] nums) {
        int m = nums.length;
        int[] a = new int[m + 1], b = new int[m + 1];
        for (int i = 1; i <= m; i++) {
            if (nums[i - 1] == 0) a[i] = a[i - 1] + 1;
            else a[i] = a[i - 1];
        }
        for (int i = m - 1; i >= 0; i--) {
            if (nums[i] == 1) b[i] = b[i + 1] + 1;
            else b[i] = b[i + 1];
        }
        int max = Integer.MIN_VALUE;
        for (int i = 0; i <= m; i++) max = Math.max(max, a[i] + b[i]);
        List<Integer> ans = new ArrayList<>();
        for (int i = 0; i <= m; i++) if (a[i] + b[i] == max) ans.add(i);
        return ans;
    }

}
